﻿#include "anscr.h"
#include "ui_anscr.h"

anscr::anscr(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::anscr)
{
    ui->setupUi(this);
    setWindowIcon(QIcon(":/pic/picture/kafavicon.ico"));
    this->setWindowTitle("筛选");
    this->setAttribute(Qt::WA_QuitOnClose, false);
}

anscr::~anscr()
{
    delete ui;
}
void anscr::showEvent(QShowEvent *event){
    if(refDataList){
        QList<QString> realPosList;
        QList<QString> sampleNameList;
        QList<QString> sampleTypeList;
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);

        QString sql= "select distinct  "
                     "(select Name from ItemCode where dicCode=5 and Code=PositionNumber) as RealPos,"
                     "SampleName,SampleType "
                     "from sampleInfo s "
                     "join SampleAccessInfo sa on s.ID = sa.SampleGuid "
                     "Left join FluorescenceData f on s.ID = f.SampleId "
                     "order by PositionNumber,CyclesNumber;";

        query.exec(sql);

        ui->comboBox_2->blockSignals(true);
        ui->comboBox_2->DataClear();
        ui->comboBox_2->addDataItem("全部");
        realPosList.append("全部");
        while (query.next()) {
            QString realPos=query.value("RealPos").toString();
            QString sampleName=query.value("SampleName").toString();
            QString sampleType=query.value("SampleType").toString();

            if(!realPosList.contains(realPos))
            {
                realPosList.append(realPos);
                ui->comboBox_2->addDataItem(realPos);
            }

            if(!sampleNameList.contains(sampleName))
            {
                sampleNameList.append(sampleName);
            }

            if(!sampleTypeList.contains(sampleType))
            {
                sampleTypeList.append(sampleType);
            }
        }
        ui->comboBox_2->setSelectedData(realPosList);

        ui->comboBox_2->blockSignals(false);

        ui->comboBox_3->blockSignals(true);
        ui->comboBox_3->clear();
        ui->comboBox_3->addItem("全部");
        ui->comboBox_3->addItems(sampleNameList);
        ui->comboBox_3->blockSignals(false);

        ui->comboBox_4->blockSignals(true);
        ui->comboBox_4->clear();
        ui->comboBox_4->addItem("全部");
        ui->comboBox_4->addItems(sampleTypeList);
        ui->comboBox_4->blockSignals(true);

        refDataList=false;
    }
    ui->comboBox_2->SetCurrentData(posInfo);
    ui->comboBox_3->setCurrentText(sampleName);
    ui->comboBox_4->setCurrentText(testType);
}

void anscr::on_pushButton_2_clicked()
{
    this->close();
}

void anscr::on_pushButton_3_clicked()
{
    posInfo = ui->comboBox_2->currentText();
    sampleName = ui->comboBox_3->currentText();
    testType = ui->comboBox_4->currentText();
    this->close();
}
